require 'gadgets/combobox'
module EventEditor
  module Commands
    class Pause
      @@icon = Gdk::Pixbuf.new("icon/command/mes.xpm")
      def self.show(base, model, edit_command = [], options = {}, &func)
       @dialog = Gtk::Dialog.new("Pause",
               base,
               Gtk::Dialog::MODAL,
               ["OK", Gtk::Dialog::RESPONSE_OK],
               ["Cancel", Gtk::Dialog::RESPONSE_CANCEL]
               )

        @model = model
        @dialog.vbox.add(self.create_panel)
        @dialog.vbox.show_all

        self.load(edit_command)
        
        @dialog.run do |response|
          if response == Gtk::Dialog::RESPONSE_OK
            func.call(self.command)
          end
        end
        @dialog.destroy
      end
      
      def self.create_panel
        ## Create document
        box = Gtk::VBox.new
        
        # Speaker Selection
        @event_combobox = ::Gadgets::Combobox.new(@model.event_select_list(:all), [String, Integer])
        @bool_combobox = ::Gadgets::Combobox.new([["on", "on"], ["off", "off"]], [String, String])

        box.add(@event_combobox)
        box.add(@bool_combobox)
        return box
      end
      
      def self.load(edit_command)
        if edit_command.empty?
          
        else
          @event_combobox.select(edit_command[1])
        end
      end
      
      def self.command
        return ['pause', @event_combobox.selected_data, @bool_combobox.selected_data]
      end
      
      def self.command_to_s(model, args, margin = "")
        arr = {"off" => "off", "on" => "on"}
        name = '[<span color="red">invalid</span>]'
        model.event_select_list.each do |t|
          if t[1] == args[1]
            name = "[ " + t[0] + " ]"
            break
          end
        end
        
        s = "<b>Pause:</b> #{name} #{arr[args[2]]}"

        return s
      end
      
      def self.icon
        return @@icon
      end
    end
  end
end